package com.chzc.goods.controller;

/**
 * @author cv大魔王
 * @version 1.0
 * @date 2021/6/20 19:41
 */

import cn.dev33.satoken.stp.SaTokenInfo;
import cn.dev33.satoken.stp.StpUtil;
import com.chzc.sys.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api(value = "模拟登录", tags = "模拟登录")
@RestController
@RequestMapping("/pub/login/all")
public class LoginTestController {

    @Autowired
    private IUserService userService;

    @ApiOperation("生成令牌")
    @GetMapping("/{number}")
    @ApiImplicitParam(name = "number", value = "登录数量", required = true)
    public ArrayList<Map<String, String>> placeAnOrder(@PathVariable Integer number) {
        ArrayList<Map<String, String>> tokenList = new ArrayList<>();

        List<String> ids = userService.findAllId();

        for (Integer i = 0; i < number; i++) {
            StpUtil.login(ids.get(i));
            SaTokenInfo tokenInfo = StpUtil.getTokenInfo();
            tokenList.add(new HashMap<String, String>(){{
                put("token", tokenInfo.getTokenValue());
            }});
        }
        return tokenList;
    }

}
